﻿//-----------------------------------------------------------------------
// <copyright file="DefaultLinkProvider.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>10/04/2013</date>
//-----------------------------------------------------------------------

using ConsoleHoster.Common.Model;
using ConsoleHoster.Common.Utilities;
using ConsoleHoster.Model.NativeWrappers;
using System.Windows.Forms;

namespace ConsoleHoster.ViewModel
{
	internal class DefaultLinkProvider : IImportLinkProvider
	{
		private readonly ILogger logger;

		public DefaultLinkProvider(ILogger argLogger)
		{
			this.logger = new ComponentLogger("DefaultLinkProvider", argLogger);
		}

		public string GetLink()
		{
			string tmpResult = null;
			using (OpenFileDialog tmpDialog = new OpenFileDialog())
			{
				tmpDialog.Multiselect = false;
				tmpDialog.Filter = "Shortcuts|*.lnk";
				DialogResult tmpDialogResult = tmpDialog.ShowDialog();
				if (tmpDialogResult == DialogResult.OK)
				{
					tmpResult = tmpDialog.FileName;
				}
			}

			return tmpResult;
		}

		public IWindowsShortcut GetShortcut()
		{
			IWindowsShortcut tmpResult = null;

			string tmpLink = this.GetLink();
			if (tmpLink != null)
			{
				tmpResult = new WindowsShortcut(tmpLink);
			}

			return tmpResult;
		}
	}
}
